import os
import sys
import time

import cv2
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QImage
from PyQt5.QtWidgets import QMessageBox, QApplication
from pypinyin import lazy_pinyin, Style
from ui.zuce import Ui_MainWindow
from PyQt5 import QtCore, QtGui, QtWidgets
import pymysql

class zc(QtWidgets.QMainWindow,Ui_MainWindow):
    def __init__(self,data):
        super(zc,self).__init__()
        self.setupUi(self)
        self.data=data

        self.setWindowFlags(Qt.WindowMinimizeButtonHint)

        self.initsold()


    def initsold(self):

        self.pushButton.clicked.connect(self.save_image)
        self.pushButton_2.clicked.connect(self.guanbi)
    #关闭界面
    def guanbi(self):
        self.close()

    #保存信息
    def save_image(self):
        # if self.she==True:
            if self.lineEdit_bl.text() == "" and self.lineEdit_gender.text() == "" and self.lineEdit_age.text() == "" and self.lineEdit_name.text() == "" and self.lineEdit_phone.text() == "":
                QMessageBox.information(self, "提示", "请先填写信息", QMessageBox.Ok)
            else:
                #连接数据库
                conn = pymysql.connect(
                    host='localhost',  # 主机名
                    port=3306,  # 端口号
                    user='root',  # 用户名
                    password='xjy123456',  # 密码
                    autocommit=True  # 自动提交更改
                )
                cursor = conn.cursor()
                # 选择数据库
                conn.select_db('face_recognition')
                sql = "insert into face values ('{}','{}','{}','{}','{}','{}');".format(self.lineEdit_name.text(),
                                                                                        self.lineEdit_age.text(),
                                                                                        self.lineEdit_gender.text(),
                                                                                        self.lineEdit_phone.text(),
                                                                                        self.lineEdit_bl.text(), self.data)
                cursor.execute(sql)
                cursor.close()  # 关闭游标
                conn.close()  # 关闭连接
                # 显示信息提示
                QMessageBox.information(self, "提示", "信息已保存", QMessageBox.Ok)




if __name__ == '__main__':
    QApplication.setHighDpiScaleFactorRoundingPolicy(Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
    # 适应高DPI设备
    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    # 解决图片在不同分辨率显示模糊问题
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = zc()
    MainWindow.show()
    sys.exit(app.exec_())
